home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 4 / ETO Development Tools 4.iso / Tools - Objects / MacsBug / MacsBug 6.2.1 / dcmds / C Samples / Heap.c < prev    next >
Text File  |  1991-05-01  |  2KB  |  81 lines

  1. /* Heap.c
  2.  
  3.    The following MPW commands will build the dcmd and copy it to the
  4.    "Debugger Prefs" file in the System folder. The dcmd's name in
  5.    MacsBug will be the name of the file built by the Linker.
  6.  
  7.         C Heap.c -b
  8.         Link {dcmdLib}dcmdGlue.a.o Heap.c.o {dcmdLib}DRuntime.o {CLibraries}StdCLib.o -o Heap
  9.         BuildDcmd Heap 100
  10.         Echo 'include "Heap";'    |    Rez -a -o "{systemFolder}Debugger Prefs"
  11.  */
  12.  
  13. #include <Types.h>
  14. #include "dcmd.h"
  15.  
  16.  
  17. void NumberToHex (long number, Str255 hex)
  18. {
  19.     Str255    digits = "0123456789ABCDEF";
  20.     int        n;
  21.  
  22.     strcpy (hex, &".00000000");
  23.     hex[0] = 8;
  24.     for (n = 8; n >= 1; n--)
  25.         {
  26.         hex[n] = digits[number % 16];
  27.         number = number / 16;
  28.         }
  29. } // NumberToHex
  30.  
  31.  
  32. pascal void DisplayBlockInfo (long blockAddress, long blockLength, long masterPtr, short blockType, Boolean locked, Boolean purgeable, Boolean resource)
  33. {
  34.     Str255 value;
  35.  
  36.     NumberToHex (blockAddress, value);
  37.     dcmdDrawLine (value);
  38.  
  39.     NumberToHex (blockLength, value);
  40.     dcmdDrawString ("\p ");
  41.     dcmdDrawString (value);
  42.  
  43.     if (blockType == relocatableBlock)
  44.         {
  45.         NumberToHex (masterPtr, value);
  46.         dcmdDrawString ("\p ");
  47.         dcmdDrawString (value);
  48.  
  49.         dcmdDrawString ("\p ");
  50.         if (locked)
  51.             { dcmdDrawString ("\pLocked "); }
  52.         if (purgeable)
  53.             { dcmdDrawString ("\pPurgeable "); }
  54.         if (resource)
  55.             { dcmdDrawString ("\pResource "); }
  56.         }
  57. } // DisplayBlockInfo
  58.  
  59.  
  60. pascal void CommandEntry (dcmdBlock* paramPtr)
  61. {
  62.     switch (paramPtr->request)
  63.         {
  64.         case dcmdInit:
  65.             break;
  66.  
  67.         case dcmdHelp:
  68.             dcmdDrawLine ("\pHEAP");
  69.             dcmdDrawLine ("\p   Displays information about all heap blocks");
  70.             break;
  71.  
  72.         case dcmdDoIt:
  73.             // Draw the column labels
  74.             dcmdDrawLine ("\p  Address   Length  Mstr Ptr");
  75.  
  76.             // The MacsBug heap iterator will call DisplayBlockInfo once for each block in the heap
  77.             dcmdForAllHeapBlocks (DisplayBlockInfo);
  78.             break;
  79.         }
  80. } // CommandEntry
  81.